package com.kungfuhacking.wristbandpro.chat.activity;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.kungfuhacking.wristbandpro.R;
import com.kungfuhacking.wristbandpro.base.view.BaseActivity;
import com.kungfuhacking.wristbandpro.utils.CommonUtils;

import org.greenrobot.eventbus.EventBus;

/**
 * 拍照后预览
 * Created by Aaron on 17/5/22.
 */

public class ShowPhotoActivity extends BaseActivity implements View.OnClickListener {

    private SimpleDraweeView ivphoto;
    private RelativeLayout rltop;

    private boolean isHint;
    private String photoUrl;
    private Bitmap bitmapFromPath;
    private String TAG = getClass().getSimpleName();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_show_photo);

        isHint = false;
        initWidget();
        photoUrl = getIntent().getStringExtra("photoUrl");

        Log.d(TAG, "图片的路径:" + photoUrl);//13811365683     18500226732   18515576731

        bitmapFromPath = CommonUtils.getBitmapFromPath(photoUrl);
        ivphoto.setImageBitmap(bitmapFromPath);

    }

    private void initWidget() {

        this.rltop = (RelativeLayout) findViewById(R.id.rl_top);
        TextView tvsend = (TextView) findViewById(R.id.tv_send);
        ImageView ivback = (ImageView) findViewById(R.id.iv_back);
        this.ivphoto = (SimpleDraweeView) findViewById(R.id.iv_photo);

        ivphoto.setOnClickListener(this);
        ivback.setOnClickListener(this);
        tvsend.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {

        switch (v.getId()) {

            case R.id.iv_photo:

                rltop.setVisibility(isHint ? View.VISIBLE : View.GONE);
                isHint = !isHint;

                break;

            case R.id.iv_back://返回
                finish();
                break;

            case R.id.tv_send://发送

                EventBus.getDefault().post(photoUrl);
                if (bitmapFromPath != null) {
                    bitmapFromPath.recycle();
                }
                finish();

                break;

        }

    }

}
